<template>
  <t-dialog
    header="评审判定"
    :visible.sync="visible"
    :onClose="closeDialog"
    :closeOnOverlayClick="false"
    @confirm="onSubmit"
    :confirmBtn="{
        content: loading?'提交中...':'确认',
        theme: 'primary',
        loading: loading,
      }"
    width="60%"
    top="5%"
  >
    <div style="height: 65vh">
      <t-form ref="form" :colon="true" :data="formData" labelWidth="100px" :rules="rules">

        <t-form-item label="标准名称：">
          <a @click="dialog.header=projectName;dialog.open_detail=true">{{projectName}}</a>
        </t-form-item>
        <t-form-item label="评审类型：" name="reviewType">
          <t-select style="width: 390px" disabled  placeholder="评审业务类型" clearable filterable :options="dict.type.bzh_review_type"
                    v-model="formData.reviewType">
          </t-select>
        </t-form-item>
        <t-form-item label="是否通过：" name="projectStatus" >
          <t-radio-group v-model="formData.projectStatus">
            <t-radio value="1"> 是</t-radio>
            <t-radio value="2">需要复议</t-radio>
            <t-radio value="0"> 否</t-radio>
          </t-radio-group>
        </t-form-item>
        <t-form-item label="备注：" name="content">
          <t-textarea
            clearable :autosize="{minRows: 5}"
            v-model="formData.content"
            placeholder="请输入内容"
          />
        </t-form-item>
      </t-form>
      <standardDetailDialog :objId="objId" :header="dialog.header"  :visible.sync="dialog.open_detail" v-if="dialog.open_detail">
      </standardDetailDialog>
    </div>
  </t-dialog>
</template>

<script>
import standardDetailDialog from "@/pages/bzh/standard/components/standard-detail-dialog.vue";

export default {
  name: "project-approval",
  dicts: ['sys_normal_disable', 'subject_classification', 'bzh_review_type','project_type'],
  components:{
    standardDetailDialog,
  },
  props:["objId","reviewType","projectName",'businessId'],
  data(){
    return {
      dialog:{
        header:'',
        open_detail: false,
        objId: null
      },
      visible: true,
      loading: false,
      projectStatusOptions:[],
      projectCategoryData: [],
      formData:{
        id:this.objId,
        projectStatus:'1',
        reviewType: this.reviewType,
        content: '',
        businessId: this.businessId,
        projectNum: '',
        projectCategory: '',
        subjectClassification: '',
        projectType: '',
      },
      rules:{
        projectCategory: [
          { required: true, message: "计划类别不能为空"}
        ],
        // subjectClassification: [
        //   { required: true, message: "学科分类不能为空"}
        // ],
        projectType: [
          { required: true, message: "项目类型不能为空"}
        ],
        projectNum: [
          { required: true, message: "项目编号不能为空"}
        ],
        content: [
          { required: true, message: "评审意见不能为空"}
        ],
        score: [
          {required: true, validator: (val) => val >= 0, message: "大于等于0", type: "error"}
        ],
        projectStatus: [
          { required: true, message: "状态不能为空"}
        ],
      }
    }
  },
  async created() {
    this.getReviewResult();
    // setTimeout(()=>{
    //   this.formData.reviewType = this.reviewType;
    // },1000);
  },
  methods:{
    getReviewResult(){
      // 获取评审信息
      this.$api.bzh.review.projectReviewTeamGet(this.objId).then(response=>{
        if(response.data){
          Object.assign(this.formData, response.data)
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    closeDialog() {
      this.$emit("update:visible", false);
    },
    onSubmit() {
      this.$refs.form.validate().then((validateResult) => {
        if (validateResult === true) {
          this.loading = true;
          this.$api.bzh.review.teamProjectReviewUpdate(this.formData).then(reponse=>{
            this.$message.success("提交成功");
            this.$emit("reload");
            this.$emit("update:visible", false);
            this.loading = false;
          }).catch((e) => {
            this.loading = false;
            this.$message.error(e.toString());
          });
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
